package com.zeny.coding.controller.admin.system;


import com.zeny.coding.constants.CourseConstants;
import com.zeny.coding.dto.Response;
import com.zeny.coding.dto.RoleUserDto;
import com.zeny.coding.service.RoleUserService;
import com.zeny.coding.util.DtoUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.xml.bind.ValidationException;

/**
 * <h2>用户-角色关系</h2>
 *
 * @Author Zeny
 */
@RequestMapping("/system/admin/roleUser")
@RestController
public class RoleUserController {

    @Autowired
    private RoleUserService roleUserService;

    @PostMapping("/saveBatch")
    public Response save(@RequestBody RoleUserDto roleUserDto) throws ValidationException {
        DtoUtil.valid(roleUserDto.getUserId(), true, 1, 19);
        this.roleUserService.saveBatch(roleUserDto);
        return new Response().success().message(CourseConstants.ASSIG_ROLE_SUCCESS);
    }
}
